﻿
@{
    ViewBag.Title = "菜单编辑";
}
@section Css{

    <link href="/Content/css/plugins/chosen/chosen.css" rel="stylesheet"/>
}
<div class="col-sm-6" style="padding-top: 10px;">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <form class="form-horizontal m-t" id="form1">
                <div class="form-group">
                    <label class="col-sm-3 control-label">模块名称：</label>
                    <div class="col-sm-8">
                        <select id="functionId" name="functionId" class="form-control"></select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">菜单名称：</label>
                    <div class="col-sm-8">
                        <input id="menuName" type="text" class="form-control" name="menuName">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">菜单地址：</label>
                    <div class="col-sm-8">
                        <input id="menuUrl" type="text" class="form-control" name="menuUrl">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">菜单排序：</label>
                    <div class="col-sm-8">
                        <input id="menuOrder" type="text" class="form-control" name="menuOrder">
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-4 col-sm-offset-3 text-center">
                        <button id="btn_Submit" class="btn btn-primary" type="button">提交</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
@section Js{
    <script src="/Content/js/plugins/chosen/chosen.jquery.js"></script>
    <script type="text/javascript">
        model = @MvcHtmlString.Create(ViewBag.Json);
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        var validator = $("#form1").validate({
            rules: {
                functionId: {
                    required: true
                },
                menuName: {
                    required: true
                },
                menuUrl: {
                    required: true
                },
                menuOrder: {
                    required: true,
                    digits: true
                }
            },
            messages: {
                functionId: {
                    required: "请选择模块"
                },
                menuName: {
                    required: "请输入菜单名称"
                },
                menuUrl: {
                    required: "请输入菜单地址"
                },
                menuOrder: {
                    required: "请输入排序号",
                    digits: "只能输入整数"
                }
            }
        });
        $(function() {
            //dataInit();
            $("#btn_Submit").click(function() {
                if (validator.form()) {
                    var parms = {
                        menuId: model.menuId,
                        functionId: $.trim($("#functionId").val()),
                        menuName: $.trim($("#menuName").val()),
                        menuUrl: $.trim($("#menuUrl").val()),
                        menuOrder: $.trim($("#menuOrder").val())
                    }
                    $.post("/Menu/MenuSave", parms, function(json) {
                        if (json.result == "success") {
                            layer.msg(json.msg, { icon: 1, time: 2000 }, function(data) {
                                parent.location.reload();
                                parent.layer.close(index);
                            });
                        } else {
                            layer.msg(json.msg, { icon: 5, time: 2000 });
                        }
                    }, "json");
                }
            });
            //初始化模块下拉列表
            $.getJSON('/Function/GetFunctionList', function(json) {
                if (json.result == "success") {
                    $.each(json.data, function(index, item) {
                        $("#functionId").append('<option value="' + item.functionId + '" >' + item.functionName + '</option>');
                    });
                    Common.dataInit();
                    if (model.menuId == 0) {
                        $("#functionId").val($("#functionId option").eq(0).val());
                    }
                    $("#functionId").chosen({
                        no_results_text: "没有找到",
                        liszt: 'updated'
                    });
                }
            });
        });


    </script>
}